package com.uenpay.oem.ui.weipay;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.uenpay.oem.R;
import com.uenpay.oem.adapter.RecharageAdapter;
import com.uenpay.service.bean.TransBankCardList;

/**
 * Created by PS on 2017/6/18.
 */

public class BankCardListDialog extends Dialog {


    private TransBankCardList mTransBankCardList;
    private oncloseclickListener nocloseclickListener; // 点击关闭的回调
    private onaddclickListenner openclickListener; // 点击添加银行卡的回调
    private ImageView dialogClose;
    private TextView dialogAddcard;
    private RecyclerView recyclview;

    public BankCardListDialog(Context context, TransBankCardList bankCardList) {
        super(context, R.style.dialog_custom);
        this.mTransBankCardList = bankCardList;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialogview);
        Window window = getWindow();
        window.setGravity(Gravity.CENTER); // 此处可以设置dialog显示的位置为居中
        //按空白处不能取消动画
        setCanceledOnTouchOutside(false);
        //初始化view
        initview();
        // 数据的填充
        initdata();
        // 初始化界面控件的事件
        initEvent();
    }

    private void initview() {
        dialogClose = (ImageView) findViewById(R.id.dialog_close);
        RelativeLayout dialyglayout = (RelativeLayout) findViewById(R.id.activity_dialog_layout);
        dialogAddcard = (TextView) findViewById(R.id.dialog_addcard);
        recyclview = (RecyclerView) findViewById(R.id.dialog_recycleview);
    }

    private void initdata() {
        if (mTransBankCardList != null && mTransBankCardList.getBankCardList().size() > 0) {
            recyclview.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
            RecharageAdapter recharageAdapter = new RecharageAdapter(mTransBankCardList);
            recyclview.setAdapter(recharageAdapter);
        }
    }

    private void initEvent() {
        // 点击关闭的回调
        dialogClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (nocloseclickListener != null) {

                    nocloseclickListener.oncloseClick();
                }
            }
        });

        // 点击添加银行卡的页面
        dialogAddcard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (openclickListener != null) {
                    openclickListener.onaddclick();
                }
            }
        });
    }

    /**
     * 设置取消按钮的显示内容和监听
     *
     * @param
     */
    public void setoncloseListener(oncloseclickListener onclseclickListener) {

        this.nocloseclickListener = onclseclickListener;
    }

    /**
     * 设置确定关闭 和添加被点击的接口
     */
    public interface oncloseclickListener {
        void oncloseClick();
    }

    /**
     * 设置添加新卡的跳转的页面
     */
    public void setonaddlistener(onaddclickListenner onaddclickListenner) {
        this.openclickListener = onaddclickListenner;
    }

    public interface onaddclickListenner {
        void onaddclick();
    }
}
